package cn.briarbear.myblog.service.impl;

import cn.briarbear.myblog.entity.vo.TagView;
import cn.briarbear.myblog.service.ITagBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.briarbear.myblog.repository.TagBlogRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * 标签博客的服务实现类
 *
 * @auther Val1ant
 * @blog http://www.val1ant.xin
 * @create 2018-05-03-13:39
 */
@Service
public class TagBlogServiceImpl implements ITagBlogService {


    @Autowired
    private TagBlogRepository tagBlogRepository;
    @Override
    public List<TagView> getAllTagView() {

        List<TagView> views = new ArrayList<>();
        List<Object> result = tagBlogRepository.selectAllTagView();
        for (Object o : result) {
            Object[] rowArray = (Object[]) o;
            TagView view = new TagView();
            view.setId((Integer) rowArray[0]);
            view.setName((String) rowArray[1]);
            Long count = (Long)rowArray[2];
            view.setNum(count.intValue());
            views.add(view);
        }

        return views;
    }
}
